﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Ozone.Views.Widget
{
    /// <summary>
    /// UCPumpFlow.xaml 的交互逻辑
    /// </summary>
    public partial class UCPumpFlow : UserControl
    {
        public UCPumpFlow()
        {
            InitializeComponent();
        }

        bool bIsStart = false;

        public void AnimationTask()
        {
            bIsStart = true;
            Task.Run(() =>
            {
                while (bIsStart)
                {
                    Thread.Sleep(600);
                    this.Dispatcher.Invoke(new Action(
                        delegate
                        {
                            try
                            {
                                if (pumpFlow.Visibility == Visibility.Collapsed)
                                    pumpFlow.Visibility = Visibility.Visible;
                                else
                                    pumpFlow.Visibility = Visibility.Collapsed;

                            }
                            catch (Exception)
                            {

                            }
                        }
                        )
                    );


                }
            });
        }


        public void Start()
        {
            if (!bIsStart)
                AnimationTask();
        }

        public void Stop()
        {
            if (bIsStart)
                bIsStart = false;

            this.Dispatcher.Invoke(new Action(
                       delegate
                       {
                           try
                           {
                               pumpFlow.Visibility = Visibility.Collapsed;

                           }
                           catch (Exception)
                           {

                           }
                       }
                       )
                   );
        }
    }
}
